import { http } from "@/utils/http";

/** 告警场景模型定义 */
export type AlertSceneModel = {
  id: number;
  name: string;
  englishName: string;
  type: string;
  deptId: number;
  level: number;
  frequency: number;
  noticeType: string;
  remark: string;
  createdAt: string;
  updatedAt: string;
  bindTo: number;
  judgeMark: string;
};

/** 分页获取告警场景列表 */
export const getAlertSceneListApi = (data: IReqPagerData) => {
  return http.request<Resp<IRespPagerData<AlertSceneModel>>>(
    "get",
    "/alert-scene/page-list",
    { params: data }
  );
};

/** 新增告警场景 */
export const addAlertSceneApi = (data: Partial<AlertSceneModel>) => {
  return http.request<Resp<null>>("post", "/alert-scene", { data });
};

/** 更新告警场景 */
export const updateAlertSceneApi = (id: number, data: Partial<AlertSceneModel>) => {
  return http.request<Resp<null>>("put", `/alert-scene/${id}`, { data });
};

/** 更新告警场景状态 */
export const updateAlertSceneStatusApi = (id: number, status: number) => {
  return http.request<Resp<null>>("patch", `/alert-scene/${id}/status`, {
    data: { status }
  });
};

/** 删除告警场景 */
export const deleteAlertSceneApi = (id: number) => {
  return http.request<Resp<null>>("delete", `/alert-scene/${id}`);
};

/** 根据ID获取告警场景详情 */
export const getAlertSceneByIdApi = (id: number) => {
  return http.request<Resp<{
    info: AlertSceneModel
  }>>('get', '/alert-scene/getOne', {
    params: { id }
  });
};

/** 获取告警场景选项列表 */
export const getAlertSceneOptionsApi = (params?: { fieldKey?: string; fieldLabel?: string; deptId?:number }) => {
  return http.request<Resp<{
    options: Array<{
      label: string;
      val: string | number;
    }>
  }>>('get', '/alert-scene/getOptions', { params });
};
